<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="http://shop.wedpl.cn/favicon.ico" rel="shortcut icon" type="image/x-icon">
    <title>抢单大厅</title>
    <link rel="stylesheet" type="text/css" href="/css/login_reset.css">
    <link rel="stylesheet" type="text/css" href="/css//shop/home.css">
</head>
<body>
<div id="content">
	<div id="content_left">
		<div class="head_img">
			{% if model.url is not empty%}
				<img src="{{url}}" alt=""/>
			{% else %}
				<img src="/images/shop/logo.png"/>
			{% endif %}
			<h2 style="font-size: 2rem;font-family: inherit;font-weight: 500;line-height: 1.1;">{{ username }}</h2>	
		</div>
		<div class="account">
			<h3 style="font-size: 1.75rem;font-family: inherit;font-weight: 500;line-height: 1.1;"><img src="/images/shop/account.png" />账户余额</h3>
			<p style="font-size: 1rem;font-weight: 400;line-height: 1.5;margin-top:0;"><span>{{ total }}</span>&nbsp;<em>元</em></p>
		</div>
		<div class="order_center">
			<ul>
				<li><a href="" style="background:#E4461C"><img src="/images/shop/order_home.png"/><p>&nbsp;抢单大厅</p></a></li>
				<li><a href="/order/index.html"><img src="/images/shop/my_order.png"/><p>&nbsp;我的订单</p></a></li>
				<li><a href="/order/detail.html"><img src="/images/shop/balance.png"/><p>&nbsp;余额明细</p></a></li>
				<li>
					<a href="javascript:void(0);" class="shop_info"><img src="/images/shop/pwd.png"/><p>&nbsp;信息</p></a>
				</li>
				<li style="margin-top:0rem;display:none;" class="info_list">
					<a href="/shop/info.html" style="font-size:1rem;height:3rem;line-height:3rem;text-indent:3rem;" >商家信息</a>
                                        <a href="/password/index.html" style="font-size:1rem;height:3rem;line-height:3rem;text-indent:3rem;">修改密码</a>
				</li>
			</ul>
		</div>		


	</div>

	<div id="content_right">
		<div class="right_top">
			<img src="/images/shop/top-logo.jpg" />
			<p><span>商务热线：<em>400-186-1314</em></span></p>
			<form action="/site/logout.html" method="post">
                                <input type="hidden" name="_csrf-frontend" value=""><button type="submit" class="logout">退出系统 </button>
                        </form>
			<input type="hidden" name="_csrf-frontend" value="{{ uid }}" id="user_id">
			<input type="hidden" name="_csrf-frontend" value="{{ username }}" id="user_name">
		</div>
		<div class="rule">
			<div class="rule_des">
				<h2>抢单规则</h2>
				<p>1.成功抢单，每单<span>预扣100元</span></p>
				<p>2.未成交的订单<span>返回50元</span></p>
				<p>3.成交后将在余额内扣取5%的订单金额</p>
			</div>
			<h1><a href="javascript:void(0)" id="place_order">点我抢单</a></h1>
		</div>
		<div class="right_center">
			<ul>
				{% if data is not empty %}
					{% for k,v in data %}
					<li>
						<p>称谓：<span>{{ v.username  }}</span><em class="">&nbsp;&nbsp;{{ v.created  }}</em></p>
						<p>手机：<span>{{ v.phone }}</span><span></span></p>
						<p>婚期：<em>抢单后可见</em></p>
					</li>
					{% endfor %}
				{% endif %}
			</ul>

			<div class="get_order" style="display:none">
				<img src="/images/shop/search.gif" class="search"/>
				<img src="/images/shop/get_order.png" />
			</div>
			<div class="order_detail" style="display:none">

			</div>
			<div class="success_order" style="display:none">
				<img src="/images/shop/check_order.png" />
			</div>
		</div>
		<p></p>
	</div>

</div>
<input type="hidden" id="number"  name="" value="{{ num  }}">
<script src="/js/jQuery.js" type="text/javascript"></script>
<script src="/js/script.js" type="text/javascript"></script>
<script src="/js/home.js" type="text/javascript"></script>
<script>
	$(function(){
		
		var num = $('#number').val();

		setInterval(function(){
			
			$(".right_center ul").animate({
				marginTop: '-=50rem'
			},0,function(){
				var s = Math.abs(parseInt($(this).css("margin-top")));
				console.log(s);
				if(s >= num){
					$(this).find("li").slice(0, 1).appendTo($(this));
					$(this).css("margin-top", 0);
				}
			});
				
		},4000)
		
		$('#place_order').click(function(){
			$(this).html('抢单中');
			$(this).css('background','#3696DB');
         		$('.get_order').show();
			setTimeout(function(){
				$.ajax({
					type:'POST',
					cache:false,
					url:'/order/rob-order.html',
					data:"",
					dataType:'json',
					success:function(data){
						console.log(data);
						if(data.length !== 0 ){
							$('.get_order').hide();
							var h = '<p class="close" id="close">X</p>';
					                for(var i=0;i<data.length;i++){
								var phone = data[i].phone;
								var hidephone = phone.substr(0, 3) + '******' + phone.substr(9);
								var time = data[i].created.substr(0,10);
								h +='<div class="order_one">'+
								     	'<div class="people_name"><img src="/images/shop/icon_1.png" /><p>称谓：'+data[i].username+'</p></div>'+
								     	'<div><img src="/images/shop/icon_2.png" /><p">手机：<span id="order_phone">'+hidephone+'</span></p></div>'+
								     	'<div><img src="/images/shop/icon_3.png" /><p>婚期：<span id="order_time" style="color:#828282;">抢单成功后方可见</span></p></div>'+
									'<div><img src="/images/shop/icon_4.png" /><p>预算：<span id="order_money" style="color:#828282;">抢单成功后方可见</span></p></div>'+
									'<div><img src="/images/shop/icon_5.png" /><p>风格：<span id="order_style" style="color:#828282;">抢单成功后方可见</span></p></div>'+
									'<div><img src="/images/shop/icon_6.png" /><p>备注：<span id="order_remark" style="color:#828282;">抢单成功后方可见</span></p></div>'+
									'<div><img src="/images/shop/icon_7.png" /><p>日期：'+time+'</p></div>'+
									'<input type="hidden" id="customer"  name="" value="'+data[i].id+'">'+
									'<p class="click_order">点击抢单</p>'+
								     '</div>';	
							}
							$('.order_detail').html(h);			
							$('.order_detail').show();
							$('.get_order').hide();
							$('#close').on('click',function(){
                       						 $('.order_detail').hide();
								 $('#place_order').html('点我抢单');
								 $('#place_order').css('background','#ED4A1C');
					                })
							$('.click_order').click(function(){
								var id = $(this).parent('.order_one').find('#customer').val();
								var mythis = $(this);
								$.ajax({
									type:'POST',
                                				        cache:false,
				                                        url:'/order/click.html?id='+id,
                                        				data:"",
                                				        dataType:'json',
				                                        success:function(data){
										console.log(data);
										if(data){
											if(data.total_account <=500){
												alert("账户余额不能低于500元，请及时充值");
                                                                                                return false;
											}
											if(data.orderNums >= 2){
												alert("每个商家每天只能抢两单,和客户签约后才能继续抢单");
												return false;
											}
											if(data.MoreNums>=10){
												alert("每个商家累计最多抢十单,和客户签约后才能继续抢单");
                                                                                                return false;
											}
											if(data.nums>=3){
												alert("该客户已被抢");
                                                                                                return false;
											}
											if(data.order){
												alert("该客户已被您抢过了");
                                                                                                return false;
											}
											mythis.html('抢单成功');
											mythis.css('background','#3696DB');
			                                                                mythis.parent('.order_one').css('border','1px solid #3696DB');
											var time = data.result.time.substr(0,10);
											var phone = data.result.phone;
											mythis.parents('.order_one').find('#order_phone').html(phone);
											mythis.parents('.order_one').find('#order_time').html(time);
											mythis.parents('.order_one').find('#order_money').html(data.result.money);
											mythis.parents('.order_one').find('#order_style').html(data.result.style);
											mythis.parents('.order_one').find('#order_remark').html(data.result.remark);
											mythis.parents('.order_one').find('span').css('color','black');
											var shop_uid = $('#user_id').val();
											var uid = data.result.id;
											var username = data.result.username;
											mythis.html('抢单成功');
											console.log(uid);	
											$.ajax({
												type:'POST',
			                                                                        cache:false,
                        			                                                url:'/order/over.html',
                                                			                        data:{shop_uid:shop_uid,uid:uid,username:username,phone:phone},
                                                                        			dataType:'json',
			                                                                        success:function(data){
													
												},
												error:function(){
		
												}
											});
										}
									},
									error:function(){
        
				                                        }


								});
					                })

						}else{
							
							alert("客户已被抢完");
							$('.get_order').hide();
                                                        $('#place_order').html('点我抢单');
                                                        $('#place_order').css('background','#ED4A1C');
						}
					},
					error:function(){
	
					}
				});
			},500)
		})
		
	
	})
</script>
</body>
</html>

